home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / mac / tkMacXStubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  14.2 KB  |  706 lines  |  [TEXT/CWIE]

  1. /* 
  2.  * tkMacXStubs.c --
  3.  *
  4.  *    This file contains most of the X calls called by Tk.  Many of
  5.  * these calls are just stubs and either don't make sense on the
  6.  * Macintosh or thier implamentation just doesn't do anything.  Other
  7.  * calls will eventually be moved into other files.
  8.  *
  9.  * Copyright (c) 1995-1997 Sun Microsystems, Inc.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  *
  14.  * SCCS: @(#) tkMacXStubs.c 1.84 97/05/06 14:13:58
  15.  */
  16.  
  17. #include "tkInt.h"
  18. #include <X.h>
  19. #include <Xlib.h>
  20. #include <stdio.h>
  21. #include <tcl.h>
  22.  
  23. #include <Xatom.h>
  24.  
  25. #include <Windows.h>
  26. #include <Fonts.h>
  27. #include <QDOffscreen.h>
  28. #include "tkMacInt.h"
  29.  
  30. /*
  31.  * Because this file is still under major development Debugger statements are
  32.  * used through out this file.  The define TCL_DEBUG will decide whether
  33.  * the debugger statements actually call the debugger or not.
  34.  */
  35.  
  36. #ifndef TCL_DEBUG
  37. #   define Debugger()
  38. #endif
  39.  
  40. #define ROOT_ID 10
  41.  
  42. /*
  43.  * Declarations of static variables used in this file.
  44.  */
  45.  
  46. static TkDisplay *gMacDisplay = NULL; /* Macintosh display. */
  47. static char *macScreenName = "Macintosh:0";
  48.                 /* Default name of macintosh display. */
  49.  
  50. /*
  51.  * Forward declarations of procedures used in this file.
  52.  */
  53.  
  54. static XID MacXIdAlloc _ANSI_ARGS_((Display *display));
  55. static int DefaultErrorHandler _ANSI_ARGS_((Display* display,
  56.     XErrorEvent* err_evt));
  57.  
  58. /*
  59.  * Other declrations
  60.  */
  61.  
  62. int TkMacXDestroyImage _ANSI_ARGS_((XImage *image));
  63. unsigned long TkMacXGetPixel _ANSI_ARGS_((XImage *image, int x, int y));
  64. int TkMacXPutPixel _ANSI_ARGS_((XImage *image, int x, int y,
  65.     unsigned long pixel));
  66. XImage *TkMacXSubImage _ANSI_ARGS_((XImage *image, int x, int y, 
  67.     unsigned int width, unsigned int height));
  68. int TkMacXAddPixel _ANSI_ARGS_((XImage *image, long value));
  69. int _XInitImageFuncPtrs _ANSI_ARGS_((XImage *image));
  70.  
  71. /*
  72.  *----------------------------------------------------------------------
  73.  *
  74.  * TkpOpenDisplay --
  75.  *
  76.  *    Create the Display structure and fill it with device
  77.  *    specific information.
  78.  *
  79.  * Results:
  80.  *    Returns a Display structure on success or NULL on failure.
  81.  *
  82.  * Side effects:
  83.  *    Allocates a new Display structure.
  84.  *
  85.  *----------------------------------------------------------------------
  86.  */
  87.  
  88. TkDisplay *
  89. TkpOpenDisplay(
  90.     char *display_name)
  91. {
  92.     Display *display;
  93.     Screen *screen;
  94.     GDHandle graphicsDevice;
  95.  
  96.     if (gMacDisplay != NULL) {
  97.     if (strcmp(gMacDisplay->display->display_name, display_name) == 0) {
  98.         return gMacDisplay;
  99.     } else {
  100.         return NULL;
  101.     }
  102.     }
  103.  
  104.     graphicsDevice = GetMainDevice();
  105.     display = (Display *) ckalloc(sizeof(Display));
  106.     display->resource_alloc = MacXIdAlloc;
  107.     screen = (Screen *) ckalloc(sizeof(Screen) * 2);
  108.     display->default_screen = 0;
  109.     display->request = 0;
  110.     display->nscreens = 1;
  111.     display->screens = screen;
  112.     display->display_name = macScreenName;
  113.     display->qlen = 0;
  114.     
  115.     screen->root = ROOT_ID;
  116.     screen->display = display;
  117.     screen->root_depth = 24;    /* Todo: get max depth */
  118.     screen->height = (*graphicsDevice)->gdRect.bottom -
  119.     (*graphicsDevice)->gdRect.top;
  120.     screen->width = (*graphicsDevice)->gdRect.right -
  121.     (*graphicsDevice)->gdRect.left;
  122.     screen->mwidth = (screen->width * 254 + 360) / 720;
  123.     screen->mheight = (screen->height * 254 + 360) / 720;
  124.     screen->black_pixel = 0x00000000;
  125.     screen->white_pixel = 0x00FFFFFF;
  126.     screen->root_visual = (Visual *) ckalloc(sizeof(Visual));
  127.     screen->root_visual->visualid = 0;
  128.     screen->root_visual->class = TrueColor;
  129.     screen->root_visual->red_mask = 0x00FF0000;
  130.     screen->root_visual->green_mask = 0x0000FF00;
  131.     screen->root_visual->blue_mask = 0x000000FF;
  132.     screen->root_visual->bits_per_rgb = 24;
  133.     screen->root_visual->map_entries = 2 ^ 8;
  134.  
  135.     gMacDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
  136.     gMacDisplay->display = display;
  137.     return gMacDisplay;
  138. }
  139.  
  140. /*
  141.  *----------------------------------------------------------------------
  142.  *
  143.  * TkpCloseDisplay --
  144.  *
  145.  *    Deallocates a display structure created by TkpOpenDisplay.
  146.  *
  147.  * Results:
  148.  *    None.
  149.  *
  150.  * Side effects:
  151.  *    Frees memory.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155.  
  156. void
  157. TkpCloseDisplay(
  158.     TkDisplay *displayPtr)
  159. {
  160.     Display *display = displayPtr->display;
  161.     if (gMacDisplay != displayPtr) {
  162.         panic("TkpCloseDisplay: tried to call TkpCloseDisplay on bad display");
  163.     }
  164.  
  165.     /*
  166.      * Make sure that the local scrap is transfered to the global
  167.      * scrap if needed.
  168.      */
  169.  
  170.     TkSuspendClipboard();
  171.  
  172.     gMacDisplay = NULL;
  173.     if (display->screens != (Screen *) NULL) {
  174.         if (display->screens->root_visual != (Visual *) NULL) {
  175.             ckfree((char *) display->screens->root_visual);
  176.         }
  177.         ckfree((char *) display->screens);
  178.     }
  179.     ckfree((char *) display);
  180.     ckfree((char *) displayPtr);
  181. }
  182.  
  183. /*
  184.  *----------------------------------------------------------------------
  185.  *
  186.  * MacXIdAlloc --
  187.  *
  188.  *    This procedure is invoked by Xlib as the resource allocator
  189.  *    for a display.
  190.  *
  191.  * Results:
  192.  *    The return value is an X resource identifier that isn't currently
  193.  *    in use.
  194.  *
  195.  * Side effects:
  196.  *    The identifier is removed from the stack of free identifiers,
  197.  *    if it was previously on the stack.
  198.  *
  199.  *----------------------------------------------------------------------
  200.  */
  201.  
  202. static XID
  203. MacXIdAlloc(
  204.     Display *display)            /* Display for which to allocate. */
  205. {
  206.     static long int cur_id = 100;
  207.     /*
  208.      * Some special XIds are reserved
  209.      *   - this is why we start at 100
  210.      */
  211.  
  212.     return ++cur_id;
  213. }
  214.  
  215. /*
  216.  *----------------------------------------------------------------------
  217.  *
  218.  * TkpWindowWasRecentlyDeleted --
  219.  *
  220.  *    Tries to determine whether the given window was recently deleted.
  221.  *    Called from the generic code error handler to attempt to deal with
  222.  *    async BadWindow errors under some circumstances.
  223.  *
  224.  * Results:
  225.  *    Always 0, we do not keep this information on the Mac, so we do not
  226.  *    know whether the window was destroyed.
  227.  *
  228.  * Side effects:
  229.  *    None.
  230.  *
  231.  *----------------------------------------------------------------------
  232.  */
  233.  
  234. int
  235. TkpWindowWasRecentlyDeleted(
  236.     Window win,
  237.     TkDisplay *dispPtr)
  238. {
  239.     return 0;
  240. }
  241.  
  242. /*
  243.  *----------------------------------------------------------------------
  244.  *
  245.  * DefaultErrorHandler --
  246.  *
  247.  *    This procedure is the default X error handler.  Tk uses it's
  248.  *    own error handler so this call should never be called.
  249.  *
  250.  * Results:
  251.  *    None.
  252.  *
  253.  * Side effects:
  254.  *    This function will call panic and exit.
  255.  *
  256.  *----------------------------------------------------------------------
  257.  */
  258.  
  259. static int
  260. DefaultErrorHandler(
  261.     Display* display,
  262.     XErrorEvent* err_evt)
  263. {
  264.     /*
  265.      * This call should never be called.  Tk replaces
  266.      * it with its own error handler.
  267.      */
  268.     panic("Warning hit bogus error handler!");
  269.     return 0;
  270. }
  271.  
  272.  
  273. char *
  274. XGetAtomName(
  275.     Display * display,
  276.     Atom atom)
  277. {
  278.     display->request++;
  279.     return NULL;
  280. }
  281.  
  282. int
  283. _XInitImageFuncPtrs(XImage *image)
  284. {
  285.     return 0;
  286. }
  287.  
  288. XErrorHandler
  289. XSetErrorHandler(
  290.     XErrorHandler handler)
  291. {
  292.     return DefaultErrorHandler;
  293. }
  294.  
  295. Window
  296. XRootWindow(Display *display, int screen_number)
  297. {
  298.     display->request++;
  299.     return ROOT_ID;
  300. }
  301.  
  302. XImage *
  303. XGetImage(display, d, x, y, width, height, plane_mask, format)
  304.     Display *display;
  305.     Drawable d;
  306.     int x;
  307.     int y;
  308.     unsigned int width;
  309.     unsigned int height;
  310.     unsigned long plane_mask;
  311.     int format;
  312. {
  313.     Debugger();
  314.     return NULL;
  315. }
  316.  
  317. int
  318. XGetGeometry(display, d, root_return, x_return, y_return, width_return,
  319.     height_return, border_width_return, depth_return)
  320.     Display* display;
  321.     Drawable d;
  322.     Window* root_return;
  323.     int* x_return;
  324.     int* y_return;
  325.     unsigned int* width_return;
  326.     unsigned int* height_return;
  327.     unsigned int* border_width_return;
  328.     unsigned int* depth_return;
  329. {
  330.     /* Used in tkCanvPs.c & wm code */
  331.     Debugger();
  332.     return 0;
  333. }
  334.  
  335. void
  336. XChangeProperty(
  337.     Display* display,
  338.     Window w,
  339.     Atom property,
  340.     Atom type,
  341.     int format,
  342.     int mode,
  343.     _Xconst unsigned char* data,
  344.     int nelements)
  345. {
  346.     Debugger();
  347. }
  348.  
  349. void
  350. XSelectInput(
  351.     Display* display,
  352.     Window w,
  353.     long event_mask)
  354. {
  355.     Debugger();
  356. }
  357.  
  358. void
  359. XBell(
  360.     Display* display,
  361.     int percent)
  362. {
  363.     SysBeep(percent);
  364. }
  365.  
  366. void
  367. XSetWMNormalHints(
  368.     Display* display,
  369.     Window w,
  370.     XSizeHints* hints)
  371. {
  372.     /*
  373.      * Do nothing.  Shouldn't even be called.
  374.      */
  375. }
  376.  
  377. XSizeHints *
  378. XAllocSizeHints()
  379. {
  380.     /*
  381.      * Always return NULL.  Tk code checks to see if NULL
  382.      * is returned & does nothing if it is.
  383.      */
  384.     
  385.     return NULL;
  386. }
  387.  
  388. XImage * 
  389. XCreateImage(
  390.     Display* display,
  391.     Visual* visual,
  392.     unsigned int depth,
  393.     int format,
  394.     int offset,
  395.     char* data,
  396.     unsigned int width,
  397.     unsigned int height,
  398.     int bitmap_pad,
  399.     int bytes_per_line)
  400.     XImage *ximage;
  401.  
  402.     display->request++;
  403.     ximage = (XImage *) ckalloc(sizeof(XImage));
  404.  
  405.     ximage->height = height;
  406.     ximage->width = width;
  407.     ximage->depth = depth;
  408.     ximage->xoffset = offset;
  409.     ximage->format = format;
  410.     ximage->data = data;
  411.     ximage->bitmap_pad = bitmap_pad;
  412.     if (bytes_per_line == 0) {
  413.     ximage->bytes_per_line = width * 4;  /* assuming 32 bits per pixel */
  414.     } else {
  415.     ximage->bytes_per_line = bytes_per_line;
  416.     }
  417.  
  418.     if (format == ZPixmap) {
  419.     ximage->bits_per_pixel = 32;
  420.     ximage->bitmap_unit = 32;
  421.     } else {
  422.     ximage->bits_per_pixel = 1;
  423.     ximage->bitmap_unit = 8;
  424.     }
  425.     ximage->byte_order = LSBFirst;
  426.     ximage->bitmap_bit_order = LSBFirst;
  427.     ximage->red_mask = 0x00FF0000;
  428.     ximage->green_mask = 0x0000FF00;
  429.     ximage->blue_mask = 0x000000FF;
  430.  
  431.     ximage->f.destroy_image = TkMacXDestroyImage;
  432.     ximage->f.get_pixel = TkMacXGetPixel;
  433.     ximage->f.put_pixel = TkMacXPutPixel;
  434.     ximage->f.sub_image = TkMacXSubImage;
  435.     ximage->f.add_pixel = TkMacXAddPixel;
  436.  
  437.     return ximage;
  438. }
  439.  
  440. GContext
  441. XGContextFromGC(
  442.     GC gc)
  443. {
  444.     /* TODO - currently a no-op */
  445.     return 0;
  446. }
  447.  
  448. Status
  449. XSendEvent(
  450.     Display* display,
  451.     Window w,
  452.     Bool propagate,
  453.     long event_mask,
  454.     XEvent* event_send)
  455. {
  456.     Debugger();
  457.     return 0;
  458. }
  459.  
  460. int
  461. XGetWindowProperty(
  462.     Display *display,
  463.     Window w,
  464.     Atom property,
  465.     long long_offset,
  466.     long long_length,
  467.     Bool delete,
  468.     Atom req_type,
  469.     Atom *actual_type_return,
  470.     int *actual_format_return,
  471.     unsigned long *nitems_return,
  472.     unsigned long *bytes_after_return,
  473.     unsigned char ** prop_return)
  474. {
  475.     display->request++;
  476.     *actual_type_return = None;
  477.     *actual_format_return = *bytes_after_return = 0;
  478.     *nitems_return = 0;
  479.     return 0;
  480. }
  481.  
  482. void
  483. XRefreshKeyboardMapping()
  484. {
  485.     /* used by tkXEvent.c */
  486.     Debugger();
  487. }
  488.  
  489. void 
  490. XSetIconName(
  491.     Display* display,
  492.     Window w,
  493.     const char *icon_name)
  494. {
  495.     /*
  496.      * This is a no-op, no icon name for Macs.
  497.      */
  498.     display->request++;
  499. }
  500.  
  501. void 
  502. XForceScreenSaver(
  503.     Display* display,
  504.     int mode)
  505. {
  506.     /* 
  507.      * This function is just a no-op.  It is defined to 
  508.      * reset the screen saver.  However, there is no real
  509.      * way to do this on a Mac.  Let me know if there is!
  510.      */
  511.     display->request++;
  512. }
  513.  
  514. /*
  515.  *----------------------------------------------------------------------
  516.  *
  517.  * TkGetServerInfo --
  518.  *
  519.  *    Given a window, this procedure returns information about
  520.  *    the window server for that window.  This procedure provides
  521.  *    the guts of the "winfo server" command.
  522.  *
  523.  * Results:
  524.  *    None.
  525.  *
  526.  * Side effects:
  527.  *    None.
  528.  *
  529.  *----------------------------------------------------------------------
  530.  */
  531.  
  532. void
  533. TkGetServerInfo(
  534.     Tcl_Interp *interp,        /* The server information is returned in
  535.                  * this interpreter's result. */
  536.     Tk_Window tkwin)        /* Token for window;  this selects a
  537.                  * particular display and server. */
  538. {
  539.     char buffer[50], buffer2[50];
  540.  
  541.     sprintf(buffer, "X%dR%d ", ProtocolVersion(Tk_Display(tkwin)),
  542.         ProtocolRevision(Tk_Display(tkwin)));
  543.     sprintf(buffer2, " %d", VendorRelease(Tk_Display(tkwin)));
  544.     Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)),
  545.         buffer2, (char *) NULL);
  546. }
  547. /*
  548.  * Image stuff 
  549.  */
  550.  
  551. int 
  552. TkMacXDestroyImage(
  553.     XImage *image)
  554. {
  555.     Debugger();
  556.     return 0;
  557. }
  558.  
  559. unsigned long 
  560. TkMacXGetPixel(
  561.     XImage *image,
  562.     int x,
  563.     int y)
  564. {
  565.     Debugger();
  566.     return 0;
  567. }
  568.  
  569. int 
  570. TkMacXPutPixel(
  571.     XImage *image,
  572.     int x,
  573.     int y,
  574.     unsigned long pixel)
  575. {
  576.     /* Debugger(); */
  577.     return 0;
  578. }
  579.  
  580. XImage *
  581. TkMacXSubImage(
  582.     XImage *image,
  583.     int x,
  584.     int y,
  585.     unsigned int width,
  586.     unsigned int height)
  587. {
  588.     Debugger();
  589.     return NULL;
  590. }
  591.  
  592. int 
  593. TkMacXAddPixel(
  594.     XImage *image,
  595.     long value)
  596. {
  597.     Debugger();
  598.     return 0;
  599. }
  600.  
  601. /*
  602.  *----------------------------------------------------------------------
  603.  *
  604.  * XChangeWindowAttributes, XSetWindowBackground,
  605.  * XSetWindowBackgroundPixmap, XSetWindowBorder, XSetWindowBorderPixmap,
  606.  * XSetWindowBorderWidth, XSetWindowColormap
  607.  *
  608.  *    These functions are all no-ops.  They all have equivilent
  609.  *    Tk calls that should always be used instead.
  610.  *
  611.  * Results:
  612.  *    None.
  613.  *
  614.  * Side effects:
  615.  *    None.
  616.  *
  617.  *----------------------------------------------------------------------
  618.  */
  619.  
  620. void
  621. XChangeWindowAttributes(
  622.     Display* display,
  623.     Window w,
  624.     unsigned long value_mask,
  625.     XSetWindowAttributes* attributes)
  626. {
  627. }
  628.  
  629. void 
  630. XSetWindowBackground(
  631.     Display *display,
  632.     Window window,
  633.     unsigned long value)
  634. {
  635. }
  636.  
  637. void
  638. XSetWindowBackgroundPixmap(
  639.     Display* display,
  640.     Window w,
  641.     Pixmap background_pixmap)
  642. {
  643. }
  644.  
  645. void
  646. XSetWindowBorder(
  647.     Display* display,
  648.     Window w,
  649.     unsigned long border_pixel)
  650. {
  651. }
  652.  
  653. void
  654. XSetWindowBorderPixmap(
  655.     Display* display,
  656.     Window w,
  657.     Pixmap border_pixmap)
  658. {
  659. }
  660.  
  661. void
  662. XSetWindowBorderWidth(
  663.     Display* display,
  664.     Window w,
  665.     unsigned int width)
  666. {
  667. }
  668.  
  669. void
  670. XSetWindowColormap(
  671.     Display* display,
  672.     Window w,
  673.     Colormap colormap)
  674. {
  675.     Debugger();
  676. }
  677.  
  678. /*
  679.  *----------------------------------------------------------------------
  680.  *
  681.  * TkGetDefaultScreenName --
  682.  *
  683.  *    Returns the name of the screen that Tk should use during
  684.  *    initialization.
  685.  *
  686.  * Results:
  687.  *    Returns a statically allocated string.
  688.  *
  689.  * Side effects:
  690.  *    None.
  691.  *
  692.  *----------------------------------------------------------------------
  693.  */
  694.  
  695. char *
  696. TkGetDefaultScreenName(
  697.     Tcl_Interp *interp,        /* Not used. */
  698.     char *screenName)        /* If NULL, use default string. */
  699. {
  700.     if ((screenName == NULL) || (screenName[0] == '\0')) {
  701.     screenName = macScreenName;
  702.     }
  703.     return screenName;
  704. }
  705.